#include "ECS/PNode.h"

namespace Piccolo
{
    PUUID PNode::GetId() const
    {
        return mId;
    }

    void PNode::SetId(const PUUID &nodeId)
    {
        mId = nodeId;
    }

    const std::string & PNode::GetName() const
    {
        return mName;
    }

    void PNode::SetName(const std::string &name)
    {
        mName = name;
    }

    const std::vector<PNode *> & PNode::GetChildren() const
    {
        return mChildren;
    }

    bool PNode::HasParent()
    {
        return mParent != nullptr;
    }

    bool PNode::HasChildren()
    {
        return !mChildren.empty();
    }

    void PNode::SetParent(PNode *node)
    {
        node->AddChild(this);
    }

    PNode * PNode::GetParent() const
    {
        return mParent;
    }

    void PNode::AddChild(PNode *node)
    {
        if (node->HasParent())
        {
            node->GetParent()->RemoveChild(node);
        }
        node->mParent = this;
        mChildren.push_back(node);
    }

    void PNode::RemoveChild(PNode *node)
    {
        if (!HasChildren()) return;
        for (auto it = mChildren.begin(); it != mChildren.end(); ++it)
        {
            if (node == *it)
            {
                mChildren.erase(it);
                break;
            }
        }
    }
}
